import re

from flask import Blueprint, request, jsonify, render_template
import pandas as pd
import requests
import json
import requests
import threading
import openpyxl
from openpyxl import Workbook

from methods.jingdongOs import submitBase
from utils.tools import dcc_book_detail

bp = Blueprint("jingdongOs", __name__, url_prefix="/jingdongOs")


@bp.route('/test', methods=['get'])
def test():
    return "test"


@bp.route('/publishProduct', methods=['post'])
def publishProduct():
    data = request.get_json()
    sessionId = data.get('sessionId')
    wareIds = data.get('wareIds')
    dcc_token = data.get('dcc_token')
    serial_no = data.get('serial_no')
    if not dcc_token or not serial_no or not sessionId or not wareIds:
        return {'code': 0, 'message': '请传入必填项！'}
    book_details_json = dcc_book_detail(serial_no, dcc_token)
    if book_details_json['code'] != 200:
        return {'code': 0, 'message': book_details_json['message']}
    # 第一步，提交基础信息
    base_result = submitBase(book_details_json, wareIds, sessionId)
    return base_result
    # cookies = {
    #     'VC_INTEGRATION_JSESSIONID': 'f1b00480-e019-4d29-96f7-52c85ff455a1',
    # }
    # params = {
    #     'wareId': '14095269',
    # }
    # response = requests.get('https://vcbooks.jd.com/sub_books/edit/init', params=params, cookies=cookies, headers={})
